package com.allen.controller;

import com.allen.bean.Mywork;
import com.allen.bean.Result;
import com.allen.bean.Work;
import com.allen.service.MyworkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;

@RestController    //相当于@Controller+@RequestBody
@RequestMapping("/mywork")
@CrossOrigin(origins ="*")
public class MyworkController {

    @Autowired
    public MyworkService myworkService;

    @RequestMapping("hello")
    public String hello(){
        return "hello";
    }

//    @RequestMapping("/subwork")
//    public String submit(){
//        return "成功进入控制器";
//    }
//
//    @RequestMapping("sel")
//    public String selwork(){
//        return "成功进入控制器";
//    }
    /**
     * 上传作品
     * @param
     * @return
     */
    @RequestMapping("subwork")
    public Result submit(Mywork mywork){
        System.out.println("成功进入控制器");
        return myworkService.submit(mywork);
    }

    /**
     * 获取作品信息界面
     * @return
     */
    @RequestMapping("selwork")
    public List<Mywork> selwork(Mywork mywork) throws SQLException {
        System.out.println("成功进入控制器");
        return myworkService.selWork(mywork);
    }

    @RequestMapping("selall")
    public List<Mywork> selall(){
        System.out.println("成功进入控制器");
        return myworkService.selall();
    }

    /**
     * 增加浏览量
     * @param work
     * @return
     */
    @RequestMapping("addeye")
    public Result addeye(Work work){
        System.out.println("成功进入浏览量控制器");
        return myworkService.add(work);
    }




}
